package com.gonsin.gnews;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.gonsin.gnews.annotations.configuration.ConfigViewModel;
import com.gonsin.gnews.annotations.model.*;
import com.gonsin.gnews.annotations.services.IConfigService;
import com.gonsin.gnews.annotations.services.IConfigValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "消息配置相关接口")
@RestController
@RequestMapping("/api/news")
public class NewsConfigController {
    @Autowired private IConfigService configService;
    @Autowired private IConfigValueService configValueService;

    @ApiOperationSupport(order = 23010)
    @ApiOperation("消息配置 - 获取配置值")
    @PostMapping("/configValues")
    public GNewsResponseResult<ConfigValueModel> getConfigValue(
            @ApiParam("租户主键")@RequestParam("edificeKey") String edificeKey,
            @ApiParam("平台")@RequestParam("platform") String platform){
        ConfigValueModel configPo = configValueService.getConfigValue(edificeKey, platform);
        return GNewsResponseResult.result(configPo);
    }

    @ApiOperationSupport(order = 23010)
    @ApiOperation("消息配置 - 修改配置值")
    @PutMapping("/configValues")
    public GNewsResponseResult<ConfigValueModel> findTemplate(
            @RequestBody ConfigValueModel model){
        ConfigValueModel bo = configValueService.updateConfigValue(model);
        return GNewsResponseResult.result(bo);
    }

    @ApiOperationSupport(order = 23011)
    @ApiOperation("消息配置 - 查询所有配置模板")
    @GetMapping("/configViews")
    public GNewsResponseResult<List<ConfigViewModel>> findAllConfigs(){
        return GNewsResponseResult.result(configService.findAllConfigs());
    }

}
